//
//  CurrentInforsViewController.m
//  YiXiProject
//
//  Created by xingshuai on 2019/8/4.
//  Copyright © 2019 iMac. All rights reserved.
//

#import "CurrentInforsViewController.h"

#import "InforTopScrollView.h"
#import "CurrentInforBottonView.h"

@interface CurrentInforsViewController () <ClickInforBtnTagDelegate>

@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) InforTopScrollView *topScrollView;   // 头部滑动 - srollview
@property (nonatomic, strong) CurrentInforBottonView *bottomView;  // bottom - View
@property (nonatomic,strong) NSDictionary *listArr;

@end

@implementation CurrentInforsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _dataArray = [[NSMutableArray alloc]init];
        
    [self creatBottomView];   // bottom - view`
    
    [self reauestInforDatas]; // 获取数据
    
}

#pragma mark -- 获取数据
-(void)reauestInforDatas
{
    kWeakSelf(self);
    [HttpDatas requestInforHomeToken:[YXUserdefaults GetDefaults:@"token"] user_id:self.user_id success:^(id  _Nonnull json) {
        
        if([json isKindOfClass:[NSDictionary class]])
        {
            if([json[@"status"]integerValue] == 200)
            {
                weakself.listArr = json[@"data"];
                                
                for (int i = 0; i < [weakself.listArr[@"photo"] count]; i ++)
                {
                    [weakself.dataArray addObject:weakself.listArr[@"photo"][i]];
                }
                
                [self creatTopHeadView];  // scrollview
                
                weakself.bottomView.nameLabel.text = [NSString stringWithFormat:@"%@ %@",weakself.listArr[@"user_name"],weakself.listArr[@"age"]];
                weakself.bottomView.jobLabel.text = weakself.listArr[@"work"];
                
                if(weakself.listArr[@"bio"] == nil || [weakself.listArr[@"bio"] isEqual:[NSNull null]])
                {
                    return;
                }
                else
                {
                    weakself.bottomView.inforLabel.text = weakself.listArr[@"bio"];
                }
            }
            else
            {
                [SVProgressHUD showSuccessWithStatus:json[@"message"]];
                [SVProgressHUD dismissWithDelay:SVPROGRESSHUDTIME];
            }
        }
        
    } failure:^(NSError * _Nonnull err) {
        
    }];
}

#pragma mark -- 初始化滑动视图 scrollview
-(void)creatTopHeadView
{
    _topScrollView = [[InforTopScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT/2+25) addImageArray:_dataArray addPlaceholderImg:self.imgStr];
    [self.view addSubview:_topScrollView];
    
    [self creatBackBtn];
}

#pragma mark -- bottom - view
-(void)creatBottomView
{
    _bottomView = [[CurrentInforBottonView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT/2+20, SCREEN_WIDTH, SCREEN_HEIGHT/2)];
    _bottomView.delegate = self;
    [self.view addSubview:_bottomView];
}
#pragma mark -- ClickInforBtnTagDelegate
-(void)clickInforBtnTagNum:(NSInteger)tagNum
{
    switch (tagNum) {
        case 100:
            NSLog(@"不喜欢");
            break;
        case 101:
            NSLog(@"收藏");
            break;
        case 102:
            NSLog(@"喜欢");
            break;
            
        default:
            break;
    }
}

#pragma mark -- backBtn
-(void)creatBackBtn
{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(SCREEN_WIDTH-90, SCREEN_HEIGHT/2, 50, 50);
    backBtn.layer.cornerRadius = 25;
    backBtn.layer.masksToBounds = YES;
    [backBtn setBackgroundImage:[UIImage imageNamed:@"infoBackDown"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:backBtn];
}

#pragma mark -- 返回
-(void)backClick
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
